#include <windows.h>
#include <iostream>
#include <process.h>
#include <conio.h>
using namespace std;

DWORD WINAPI Thread_Volodya(PVOID param){
	while(true){
		cout << "A";
		Sleep(100);
	}
	//ExitThread(0);
	return 0;
}

DWORD WINAPI Thread_Oleg(PVOID param){
	while(true){
		cout << "D";
		Sleep(100);
	}
	//ExitThread(0);
	return 0;
}

void main(){

	DWORD id;
	HANDLE hThread = CreateThread(NULL, 0, Thread_Volodya, NULL, CREATE_SUSPENDED, &id);

	HANDLE hOleg = CreateThread(NULL, 0, Thread_Oleg, NULL, NULL /*CREATE_SUSPENDED*/, 0);

	/*HANDLE hProcess = GetCurrentProcess();

	cout << "Change priority:";
	_getch();*/

	//SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);

	SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);
	SetThreadPriority(hOleg, THREAD_PRIORITY_IDLE);

	Sleep(500);
	cout << "\n\n========================== ResumeThread =======================\n\n";
	ResumeThread(hThread);

	Sleep(500);
	cout << "\n\n========================== SuspendThread =======================\n\n";
	SuspendThread(hOleg);

	Sleep(500);
	cout << "\n\n========================== TerminateThread =======================\n\n";
	ResumeThread(hOleg);
	Sleep(500);
	TerminateThread(hOleg, 10);

	Sleep(500);
	cout << "\n\n========================== TerminateThread =======================\n\n";

	HANDLE hVolodya = OpenThread(THREAD_ALL_ACCESS, FALSE, id);

	TerminateThread(hVolodya, 13);

	DWORD code;

	GetExitCodeThread(hVolodya, &code);

	cout << "hVolodya terminate with code = " << code << endl;

	_getch();

}